home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0195.ZIP / NEWINT9.LIB < prev    next >
Text File  |  1984-12-17  |  3KB  |  81 lines

  1. {@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
  2. The purchaser of these procedures and functions may include them in COMPILED
  3. programs freely, but may not sell or give away the source text.
  4.  
  5. PURPOSE : Replace the standard "Interrupt 9", the Keyboard interrupt, with
  6.           a version that returns exactly and only the SCAN CODE of each
  7.           key PRESSED or RELEASED (release scan code = scan code + 128).
  8.           Typematic and all shift keys are disabled.  In fact, for safety's
  9.           sake scan code 29 followed by 70 (Control-Break) is programmed in.
  10.  
  11. WARNING:  BE VERY SURE that the procedure "OldInt" gets executed BEFORE
  12.           you leave your program--otherwise you will be excommunicated
  13.           by your PC and have no recourse but to turn it off and on again.
  14. }
  15. var
  16.  
  17.   WatchByte    : byte absolute DSeg:$0400;    {this location for WatchByte is
  18.                                                arbitrary, but it is hard-coded
  19.                                                in the new interrupt. }
  20.   mc           : array[1..22] of byte;   {by putting the code in a variable,
  21.                                           we can easily get the ADDRESS
  22.                                           of the code and point the
  23.                                           interrupt vector to it.}
  24.   KeyIntA      : integer absolute $0000:$0024;   {these are the interrupt}
  25.   KeyIntB      : integer absolute $0000:$0026;   {vector's segment and
  26.                                                                 offset}
  27.   HoldA, HoldB       : integer;
  28.   OldByte, OlderByte : byte;  {of course!}
  29. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  30. procedure NewInt;
  31.  
  32. {Save the address of the regular interrupt, and put the address
  33.   of the new version in its place}
  34. begin
  35.   HoldA := KeyIntA;  HoldB := KeyIntB;
  36.   KeyIntA := Ofs(mc);
  37.   KeyIntB := Seg(mc);
  38. end;
  39. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  40. procedure OldInt;
  41.  
  42. {PURPOSE : restore regular keyboard interrupt}
  43.  
  44. begin
  45.   KeyIntA := HoldA; KeyIntB := HoldB;
  46. end;
  47. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  48. procedure SetUpInt;
  49.  
  50. {PURPOSE : The bytes of the array MC constitute a new keyboard interrupt
  51.            in Machine Code.  When a key is pressed, its scan code appears
  52.            in the variable WatchByte}
  53.  
  54. var
  55.   N : byte;
  56. begin
  57.   mc[1]  := $50;mc[2]  := $E4;mc[3]  := $60;mc[4]  := $A2;mc[5]  := $00;
  58.   mc[6]  := $04;mc[7]  := $E4;mc[8]  := $61;mc[9]  := $0C;mc[10] := $80;
  59.   mc[11] := $E6;mc[12] := $61;mc[13] := $24;mc[14] := $7F;mc[15] := $E6;
  60.   mc[16] := $61;mc[17] := $B0;mc[18] := $20;mc[19] := $E6;mc[20] := $20;
  61.   mc[21] := $58;mc[22] := $CF;
  62.   {mc[5] and mc[6] contain the address of WatchByte (in byte-reversed
  63.   format).  You can change WatchByte's address IF you change it here too}
  64.  
  65. end;
  66. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  67. function WatchKeys:byte;
  68.  
  69. {PURPOSE : Note when the value of WatchByte changes and report the scan code
  70.            of the key pressed.}
  71.  
  72. begin
  73.   repeat until WatchByte <> OldByte;
  74.   OlderByte := OldByte;
  75.   OldByte   := WatchByte;
  76.   WatchKeys := WatchByte;
  77.      {Here's a LITTLE protection--<Ctrl><Break> restores the old interrupt}
  78.   if (OlderByte = 29) and (OldByte = 70) then OldInt;
  79. end;
  80. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  81.